package com.lb.pdm.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.lb.pdm.entity.PersonInfo;
import com.lb.pdm.entity.vo.PersonInfoVO;
import com.lb.pdm.mapper.PersonInfoMapper;
import com.lb.pdm.service.PersonInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * <p>
 * 人员基础信息表 服务实现类
 * </p>
 *
 * @author pdm
 * @since 2025-10-29
 */
@Service
public class PersonInfoServiceImpl extends ServiceImpl<PersonInfoMapper, PersonInfo> implements PersonInfoService {

    @Override
    public PersonInfoVO getPersonByIdCard(String idCard) {
        if (!StringUtils.hasText(idCard)) {
            return null;
        }
        
        LambdaQueryWrapper<PersonInfo> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(PersonInfo::getIdCard, idCard)
                   .eq(PersonInfo::getStatus, 1); // 只查询正常状态的人员
        
        PersonInfo person = this.getOne(queryWrapper);
        
        if (person != null) {
            PersonInfoVO vo = new PersonInfoVO();
            BeanUtils.copyProperties(person, vo);
            return vo;
        }
        
        return null;
    }
}
